package cn.itsource.basic.exception;

/** 系统错误码 **/
public enum ErrorCode {

    SYSTEM_ERROR("1001","系统繁忙"),
    USER_ALREADY_EXIST("1003","用户已存在"),
    ACCOUNT_OR_PWD_ERROR("1012","账号或密码错误"),
    CONTENT_ILLEGAL("1004","内容不合法"),
    VERIFY_CODE_GENERATED_FAIL("1005","验证码生成错误"),
    IMG_CODE_EXPIRE("1006","图形验证码过期"),
    SMS_CODE_EXPIRE("1010","短信验证码过期"),
    IMG_CODE_ERROR("1007","图形验证码输入错误"),
    TIME_NOT_ARRIVED("1008","未到短信重发时间"),
    PWD_INCONSISTENT("1009","两次密码不一致"),
    SMS_CODE_ERROR("1011","短信验证码错误"),
    PARAM_ERROR("1002","参数异常");

    //错误码
    private String code;
    //错误信息
    private String message;

    ErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessageByCode(String code){
        //获取枚举中所有的字段对象数组
        ErrorCode[] values = ErrorCode.values();
        for (ErrorCode value : values) {
           if(value.getCode().equals(code)){
                return value.getMessage();
           }
        }
        return null;
    }

    public String getCode() {
        return code;
    }
    public String getMessage() {
        return message+"["+code+"]";
    }
}